/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 prefabware.com Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel;

import java.lang.reflect.Modifier;

import com.prefabware.jmodel.code.JCodable;
import com.prefabware.jmodel.code.JCodeOptions;

public enum JVisibility implements JCodable{
	// lowercase not possible, reserved java-words
	PRIVATE, PROTECTED, PUBLIC, DEFAULT;
	public String toString() {
		return this.asCode(JCodeOptions.DEFAULT);
	}

	@Override
	public String asCode(JCodeOptions options) {
		// default is blank in java
		if (name().equals(DEFAULT.name())) {
			return "";
		}
		return name().toLowerCase();
	}

	public static JVisibility getVisibility(int mod) {
		JVisibility visibility = null;
		if (Modifier.isPublic(mod)) {
			visibility = PUBLIC;
		} else if (Modifier.isProtected(mod)) {
			visibility = PROTECTED;
		} else if (Modifier.isPrivate(mod)) {
			visibility = PRIVATE;
		} else {
			// no modifier means default
			visibility = DEFAULT;
		}
		return visibility;
	}

}
